package com.duoduo.sort;

import java.util.Arrays;

/**
 * @program: algorithm
 * @description: 把数组排成最小的数
 * @author: chaidl  ！
 * @create: 2022-03-09 19:32
 */
public class 把数组排成最小的数 {
    public static void main(String[] args) {
        int[] arr={3,30,34,5,9};
        System.out.println(minNumber(arr));
    }
    public static String minNumber(int[] nums) {
        // 先定义一个字符串数组
        String [] str=new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            str[i]=String.valueOf(nums[i]);
            Arrays.sort(str,(x,y)->(x+y).compareTo(y+x));
        }
        StringBuilder builder=new StringBuilder();
        for (String s : str) {
            builder.append(s);
        }
        return builder.toString();
    }
}
